home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
CLTHREAD.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-02
|
10KB
|
316 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: class.cpp
// Title: C++ Class Libraries
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
// This module contains code for the class CL_THREAD.
//
// The code in this module may be written in C++ or C.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
//
//----------------------------------------------------------------------------
#include <class.hpp>
//----------------------------------------------------------------------------
// Description: Default constructor
// Parameters:
// Returns:
//----------------------------------------------------------------------------
FN_M CL_THREAD::CL_THREAD()
{
CL_THREAD::Initialize(CL_INIT_CLASS);
}
//----------------------------------------------------------------------------
// Description: Copy constructor
// Parameters: rccl_thread Reference to object to copy.
// Returns:
//----------------------------------------------------------------------------
FN_M CL_THREAD::CL_THREAD(RCCL_THREAD rccl_thread)
{
CL_THREAD::Initialize(CL_INIT_CLASS);
*this = rccl_thread;
}
//----------------------------------------------------------------------------
// Description: Destructor
// Parameters:
// Returns:
//----------------------------------------------------------------------------
FN_M CL_THREAD::~CL_THREAD()
{
CL_THREAD::Destroy(FALSE);
}
//----------------------------------------------------------------------------
// Description: Destroy object. Free any resources used by object.
// Normally called by destructor.
// Should allow multiple calls from various classes.
// Parameters: fDestroyAll Destroy parents also?
// Default is TRUE.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_THREAD::Destroy(BOOL fDestroyAll)
{
CL_THREAD::Initialize(CL_INIT_CLASS_VARS);
if (fDestroyAll) // Destroy parent.
CL_THREAD_PARENT::Destroy(fDestroyAll);
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Initialize object.
// Normally called by constructor.
// Should allow multiple calls from various classes.
// Parameters: sInit Initialization code. May be one of the following:
// CL_INIT_CLASS Reset class variables and
// and dynamic allocations for
// this class only.
// CL_INIT_CLASS_VARS Reset class variables for
// this class only.
// CL_INIT_VARS Reset class variables for
// this class only.
// CL_INIT_ALL Initialize class and all
// parent class, including
// dynamic memory allocation.
// Default is CL_INIT_ALL
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_THREAD::Initialize(SHORT sInit)
{
if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
CL_THREAD_PARENT::Initialize(sInit);
tid = 0;
fActive = FALSE;
if (event.IsError())
SetError(event.ErrorCode());
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Check if object is in error state.
// IsValid() && IsError() MUST NOT BE DEPENDENT ON ONE ANOTHER.
// Parameters:
// Returns: TRUE if in error state.
//----------------------------------------------------------------------------
BOOL FN_M CL_THREAD::IsError() const
{
return CL_THREAD_PARENT::IsError();
}
//----------------------------------------------------------------------------
// Description: Check if object is valid
// IsValid() && IsError() MUST NOT BE DEPENDENT ON ONE ANOTHER.
// Parameters:
// Returns: TRUE if valid
//----------------------------------------------------------------------------
BOOL FN_M CL_THREAD::IsValid() const
{
return CL_THREAD_PARENT::IsValid();
}
//----------------------------------------------------------------------------
// Description: Assignment operator
// NOTE: Don't copy object into self
// Parameters: rccl_thread Reference to right value.
// Returns: Reference to new object.
//----------------------------------------------------------------------------
RCCL_THREAD FN_M CL_THREAD::operator=(RCCL_THREAD rccl_thread)
{
if (this != &rccl_thread)
{
Invalid("CL_THREAD::operator=");
}
return (RCCL_THREAD)*this;
}
//----------------------------------------------------------------------------
// Description: Retrieve object from persistent storage
// Parameters: pcsz Name of object.
// pcszSub Sub-name of object.
// The first character of the name should be '~'.
// If NULL, no sub name is available.
// Default is NULL
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_THREAD::Retrieve(PCSZ pcsz, PCSZ pcszSub)
{
NOTUSED(pcsz);
NOTUSED(pcszSub);
Invalid("CL_THREAD::Retrieve");
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Start a thread object.
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_THREAD::Run()
{
if (IsError())
return FALSE;
if (!ThreadStart(ThreadFunc, &tid, (PVOID)this))
return FALSE;
if (tid <= 0)
return FALSE;
fActive = TRUE;
Sleep(0); // Let thread start
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Store object to persistent storage
// Parameters: pcsz Name of object.
// pcszSub Sub-name of object.
// The first character of the name should be '~'.
// If NULL, no sub name is available.
// Default is NULL
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_THREAD::Store(PCSZ pcsz, PCSZ pcszSub)
{
NOTUSED(pcsz);
NOTUSED(pcszSub);
Invalid("CL_THREAD::Store");
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Thread function.
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
VOID FN_T CL_THREAD::ThreadFunc(PVOID pv)
{
PCL_THREAD pcl_thread = (PCL_THREAD)pv;
pcl_thread->Thread(); // Call thread function
pcl_thread->tid = 0; // Clear variables
pcl_thread->fActive = FALSE;
pcl_thread->event.Post();
return ;
}
//----------------------------------------------------------------------------
// Description: Wait for thread to terminate.
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_THREAD::Wait(ULONG ulWait)
{
return event.Wait(ulWait);
}
//----------------------------------------------------------------------------
// Description: Print object value to debugging output.
// Parameters: pccl_thread Pointer to dynamic object.
// If NULL, static data elements are printed.
// Default is NULL.
// pcsz Name of object.
// If NULL, no name is displayed.
// Default is NULL.
// cLevel Display level.
// Default is zero.
// Returns:
//----------------------------------------------------------------------------
#if COMPILE_DEBUG
VOID FN_M CL_THREAD::Print(PCCL_THREAD pccl_thread, PCSZ pcsz, SIZET cLevel)
{
#if COMPILE_TEST
OutputL(cLevel, "CL_THREAD%s%s", (pcsz?"::":""), (pcsz?pcsz:""));
cLevel++;
if (pccl_thread)
{
Output(" <%p>\n", pccl_thread);
if(!pccl_thread->IsError())
{
// OutputL(cLevel, " = %d\n", pccl_thread->);
}
}
else
Output(" <NULL>\n");
CL_THREAD_PARENT::Print((CL_THREAD_PARENT _FAR_ *)pccl_thread, pcsz, cLevel);
return ;
#else
NOTUSED(cLevel);
NOTUSED(pccl_thread);
NOTUSED(pcsz);
return ;
#endif
}
#endif
//----------------------------------------------------------------------------
// Description: Run standard test suite on object.
// Parameters: sTest Test to run.
// If 0, run default tests.
// Default is 0.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
#if COMPILE_DEBUG
BOOL FN_M CL_THREAD::Test(SHORT sTest)
{
#if COMPILE_TEST
NOTUSED(sTest);
return TRUE;
#else
NOTUSED(sTest);
return TRUE;
#endif
}
#endif
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------